﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ThreeByte.ActiveDeck.Data;
using log4net;

namespace ThreeByte.ActiveDeck.Web.console
{
    public partial class Verify : System.Web.UI.Page
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(Verify));

        protected void Page_Load(object sender, EventArgs e) {
            //Get the query parameters
            try {
                string verificationKey = Request.QueryString["x"];
                Guid key = Guid.Parse(verificationKey);

                if(DataUtil.IsEmailChallengeValid(key)) {
                    //Valid
                    DataUtil.MarkEmailAsVerified(key);
                    ResultLabel.Text = "Success!  Your email address has now been verified.  Please Login to the Presenter Dashboard to enable your ability to publish presentations.";
                    Page.Header.Title = "Email Verified";
                    return;
                } else {
                    //This link has expired
                }
            } catch(Exception ex) {
                log.Error("Error verifying email address", ex);
            }

            ResultLabel.Text = "Sorry.  This link is no longer valid.  Please sign in to the Presenter Dashboard to verifiy your email address again.";
            ResultHeader.Text = "Invalid Link";
            Page.Header.Title = "Invalid Link";

            
        }
    }
}